<template>
  <div class="region">
    <div class="content">
      <div class="left">地区:</div>
      <ul>
        <li :class="{active:activeFlag===''}" @click="changeRegion('')">全部</li>
        <li v-for="region in regionArr" :key="region.value"
        :class="{active:activeFlag==region.value}"
        @click="changeRegion(region.value)">
          {{ region.name }}
        </li>
      </ul>
    </div>
  </div>
</template>

<script lang="ts" setup>
import type {
  HospitalLevelAndRegionResponseData,
  HospitalLevelAndRegionArr
} from "@/api/home/type.ts"
import {onMounted, ref} from "vue";
import {reqHospitalLevelAndRegion} from "@/api/home";

const regionArr = ref<HospitalLevelAndRegionArr>([])
const activeFlag = ref<string>("")
let $emit = defineEmits([''])

onMounted(() => {
  getRegion();
})

const changeRegion = (region: string) => {
  activeFlag.value = region
  $emit('getRegion',region)
}

const getRegion = async () => {
  let result: HospitalLevelAndRegionResponseData = await reqHospitalLevelAndRegion(
      "Beijin"
  );
  if (result.code == 200) {
    regionArr.value = result.data
  }
}
</script>

<script lang="ts">
export default {
  name: "Region"
}
</script>

<style lang="scss" scoped>
.region {
  color: #7f7f7f;
  margin-top: 10px;

  .content {
    display: flex;

    .left {
      width: 60px;
      margin-right: 10px;
    }

    ul {
      display: flex;
      flex-wrap: wrap;
    }

    li {
      margin-right: 10px;
      margin-bottom: 5px;

      &.active {
        color: #55a6fe;
      }
    }

    li:hover {
      color: #55a6fe;
      cursor: pointer;
    }
  }


}
</style>
